package com.li.shop.service.Impl;

import com.li.shop.domain.Message;
import com.li.shop.domain.MessageExample;
import com.li.shop.mapper.MessageMapper;
import com.li.shop.service.MessageService;
import io.micrometer.core.instrument.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageMapper messageMapper;

    @Override
    public List<Message> listMessage() {
        return messageMapper.listMessage();
    }

    @Override
    public List<Message> findAll(String id) {
        return messageMapper.findAll(id);
    }

    @Override
    public List<Message> findAllUser() {
        return messageMapper.findAllUser();
    }

    //
//    @Override
//    public Message findById(int msId) {
//        return messageMapper.selectByPrimaryKey(mid);
//    }
//
//    @Override
//    public List<Message> findByName(String message) {
//        return messageMapper.findBymessage(mname);
//    }
    @Override
    public int saveMessage(Message message) {
        System.out.println(message.getuId() + "messageid");
        if (StringUtils.isNotBlank(message.getMsId())) {
            //if( message.getuId()!=null ){
            //把domain类中的uId类型转化为String
            return messageMapper.updateByPrimaryKey(message);
        } else {
            return messageMapper.insert(message);
        }
    }

    @Override
    public List<Message> find(MessageExample example) {
        return messageMapper.selectByExample(example);
    }

    @Override
    public Message s(String uId, String pId) {
        MessageExample example=new MessageExample();
        example.createCriteria().andPIdEqualTo("1").andUIdEqualTo("1");
        List<Message> messages=messageMapper.selectByExample(example);
        return messages.get(0);
    }

    @Override
    public List<Message> selectByuid(MessageExample messageExample) {
        return messageMapper.selectByExample(messageExample);
    }

    @Override
    public List<Message> findUserAllMessage(String id) {
        return messageMapper.fingUserAllMes(id);
    }

    @Override
    public int deleteUserMesByPrimaryKey(String id) {
        return messageMapper.deleteByPrimaryKey(id);
    }


}
